//
//  TenderJPVC.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2022/3/18.
//  Copyright © 2022 zwb. All rights reserved.
//  出价专用

import UIKit
import Eureka

class ZyaTenderJPVC: KSFormViewController,refreshable,getDepositRemainable {
 
    lazy var footerView:UIView = {
        let v = UIView(frame:CGRect(x:0,y:0,width: KSGlobal.screenW,height:KSGlobal.screenH))
        v.backgroundColor = Theme.awModuleBgColor
        return v
    }()
    var headView = UIView()
    lazy var footbg :FormView = {
        let v = FormView(frame:CGRect(x:BgLeading,y:10,width: KSGlobal.screenW - BgLeading * 2,height:KSGlobal.screenH))
        v.backgroundColor = .clear
        v.layer.cornerRadius = ItemCornerRadius
        return v
    }()
    lazy var submitButton: KSUIButton = {
        let button = KSUIButton(titlex: "确认")
        
        return button
    }()
 
    var itemdw :KSFormHItem = {
        let appe = KSFormHAppear()
            .contentTrailing(rightPP)
            .disableStyleContentGray(true)
            .contentHight(contentHHH)
            .contentFont(UIFont.systemFont(ofSize: 17))
         let v = KSFormHItem(title: "出价单位",appearance:appe )
        v.disabled = true
         return v
    }()
    var itemr :KSFormHItem = {
        let appe = KSFormHAppear()
            .contentTrailing(rightPP)
            .assistImgStr("tenderBJ")
            .contentHight(contentHHH)
            .contentFont(UIFont.systemFont(ofSize: 17))
         let v = KSFormHItem(title: "出价人",appearance:appe )
         return v
    }()
    var itemdh :KSFormHItem = {
        let appe = KSFormHAppear()
            .contentTrailing(rightPP)
            .assistImgStr("tenderBJ")
            .phoneInput(true)
            .contentHight(contentHHH)
            .contentFont(UIFont.systemFont(ofSize: 17))
         let v = KSFormHItem(title: "联系电话",appearance:appe )
         return v
    }()
    var itemSl :KSFormHItem = {
        let appe = KSFormHAppear()
            .contentTrailing(rightPP)
            .contentHight(contentHHH)
            .contentFont(UIFont.systemFont(ofSize: 17))
         let v = KSFormHItem(title: "出价数量",appearance:appe ,type: .countV)
         return v
    }()
    var itemjg :KSFormHItem = {
        let appe = KSFormHAppear()
            .contentTrailing(rightPP)
            .contentHight(contentHHH)
         let v = KSFormHItem(title: "出价价格",appearance:appe ,type: .countV)
         return v
    }()
    var itemjg_input :KSFormHItem = {
        let appe = KSFormHAppear()
            .contentTrailing(rightPP)
            .twoDemiInput(true)
            .contentHight(contentHHH)
            .contentFont(UIFont.systemFont(ofSize: 17))
         let v = KSFormHItem(title: "出价价格",appearance:appe )
         return v
    }()
    var itemSM :KSFormHItem = {
        let appe = KSFormHAppear()
            .contentTrailing(rightPP)
            .assistImgStr("tenderBJ")
            .contentHight(contentHHH)
            .contentFont(UIFont.systemFont(ofSize: 17))
         let v = KSFormHItem(title: "出价说明",appearance:appe )
         return v
    }()
    var itemsj :KSFormHItem = {
        let appe = KSFormHAppear()
            .contentTrailing(rightPP)
            .disableStyleContentGray(true)
            .contentHight(contentHHH)
            .contentFont(UIFont.systemFont(ofSize: 17))
         let v = KSFormHItem(title: "出价时间",appearance:appe )
        v.disabled = true
         return v
    }()
    
    
    
    var sectionx :ItemSectionView = {
        let v = ItemSectionView()
        v.lab.isHidden = true
        v.btn.isHidden = true
        return v
    }()
    lazy var jpTitleView:TitleChujiaImgView = {
        let v = TitleChujiaImgView( withImg: false)
        return v
    }()
    lazy var tbinfo_V: TbInfoNewView = {
        
        var v = TbInfoNewView()
        return v
        
        
    }()
 var orizPriceRank = ""
    var one = ZyaZtbContentModel(JSON: ["":""])!
   
    var z_zb_id = ""
    var z_bid_id = ""
    var excuteType = OperateType.add
 
    var depositRemain = 0.0
 
   
  
  
 
    var origTbPrice = 0.0
    lazy var timeflagView:ZyaTimeFlagView = {
        let timeflagView = ZyaTimeFlagView()
        return timeflagView
    }()
    lazy var abandonBtn:ZyaAbandButton = {
         let v = ZyaAbandButton()
        v.setTitle("放弃", for: .normal)
        v.setImage(UIImage(named: "wenhao_white"), for: .normal)
        return v
    }()
    
    

    //    z_status   当前出价单据状态     0 未中标   1 已中标   2 已放弃
    //    z_zb_status  采购状态   0:未开始;   1:已中标;   2:进行中;    3:已结束;      4:已流标
    /// 判断时用这两个状态，因为公用的因素，这里字段需要整理
    var z_zb_status = "0"
    var z_tb_status = "0"
    let helper = ZyaTenderHelper()
    var networked = false
    var appendWidget = false
    var topH:CGFloat = 0
   
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.tableView.frame = CGRect(x:0,y:topH + 35,width: KSGlobal.screenW,height: KSGlobal.screenH)
        self.tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 150, right: 0)
        timeflagView.frame = CGRect(x:0,y:topH,width: self.view.frame.width,height: 35)
         self.view.addSubview(timeflagView)
        self.insertIds2Update()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
      
        self.view.backgroundColor = .white
        self.title = "出价"
        let navH = self.navigationController.isSome ? self.navigationController!.navigationBar.frame.height : 0
        topH = UIApplication.shared.statusBarFrame.height + navH
        
        footerView.addSubview(footbg)
        
       
     
        configAddorFIx()
      
        
        
       
        configAction()
      
       
        NotificationCenter.default.addObserver(self, selector: #selector(servertimeNotification(_:)), name: Notification.Name("servertime_notification"), object: nil)

    
        NotificationCenter.default.addObserver(self, selector: #selector(newestBillStatusNotification(_:)), name: Notification.Name(newestBillStatus_notification), object: nil)

      
      }
      @objc func newestBillStatusNotification(_ notification: Notification) {
          // 从通知中获取用户信息
          if let userInfo = notification.userInfo,
             let arr = userInfo["newestBillStatus_data"] as? [NewestModel_Z] {
            
               
               
                  let ddd = arr.filter{$0.idKey == self.one.zZbId}
                  
                  if ddd.count > 0 {
                      self.one.zParallel = ddd.first!.zParallel
                      if ddd.first!.zEndDate.unwrap != "" {
                          self.one.zEndDate = ddd.first!.zEndDate
                      }
                      if ddd.first!.zOvertimedNum.unwrap != "" {
                          self.one.zOvertimedNum = ddd.first!.zOvertimedNum
                      }
                      self.one.zMaxPrice = ddd.first!.zMaxPrice
                      self.one.zRank = ddd.first!.zMyPriceRank
                      self.one.zBidCount = ddd.first!.zBidCount
                       
                       
                      self.jpTitleView.recordApi = API.tender(.queryBidRecordList(z_zb_id: self.one.zZbId.unwrap, z_bid_id: self.one.zBidId.unwrap, z_staff_id: USERINFO.usrid.unwrap))
                      
                      self.jpTitleView.setChujiaShow(title: self.one.zTitle.unwrap, count: self.one.zBidCount.unwrap, price: self.one.zPrice.unwrap, unit: self.one.zLeastUnitNm.unwrap, rank: self.one.zRank.unwrap,z_end_price_rank: self.one.zEndPriceRank.unwrap,z_parallel: self.one.zParallel.unwrap)
   
                  }
             
              self.tableView.reloadData()
       
          }
      }
     deinit {
    
         NotificationCenter.default.removeObserver(self)
     
     }
    @objc func servertimeNotification(_ notification: Notification) {
        // 从通知中获取用户信息
        if let userInfo = notification.userInfo,
           let valueServerDate = userInfo["servertime_data"] as? Date {
            print("Received value: \(valueServerDate)")
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
            var endDate = Date()
            if let endD = dateFormatter.date(from: self.one.zEndDate.unwrap) {
                endDate = endD
            }
          
            let timeNumber = Int(endDate.timeIntervalSince1970-valueServerDate.timeIntervalSince1970)
            
            
            
            if timeNumber > 0 {
                self.refreshBtn(enable: true)
               
                     self.timeflagView.setTimeFlagInfo(status: "进行中", countDown: "距结束\(Date.getHHMMSSFormSS(seconds: timeNumber))",model: one)
                 
            } else {
                self.timeflagView.setTimeFlagInfo(status: "已结束", countDown: "\(self.one.zEndDate.unwrap)结束",model: one)
                
                self.refreshBtn(enable: false)
               
                
            }
            
            
         
         
        }
    }
    func refreshBtn(enable:Bool) {
        if enable {
            self.submitButton.button.backgroundColor = Theme.primaryColor()
            self.submitButton.button.isUserInteractionEnabled = true
        } else {
            self.submitButton.button.backgroundColor = .lightGray
            self.submitButton.button.isUserInteractionEnabled = false
        }
      
    }
    func configBtnState() {
        if self.one.zButtonState == "1" {
          abandonBtn.addTouchUpInSideAction { _ in
              self.deleteAction()
          }
           let right = UIBarButtonItem(customView: abandonBtn)
          navigationItem.rightBarButtonItem = right
      } else {
          navigationItem.rightBarButtonItem = nil
      }
    }
    func configAddorFIx() {
        if excuteType == .add {
            
        } else {
            self.configBtnState()
     
        }
        if z_bid_id.isEmpty {
            
            self.z_zb_status = one.zStatus.unwrap
            self.z_tb_status = "0"
//            self.tbinfo_V.contentStr = self.one.jpInfo.unwrap
            self.tbinfo_V.content1.multiLineTitleContentShow(contentStr: one.jpInfo.unwrap, fontx: 16)
            configHeader()
            
            self.getDepositValue { (flag,value) in
                self.depositRemain = doubleTran(value)
                self.performRow()
            }
        } else {
            self.network()
            self.tableView.mj_header = KSRefreshHeader {
                self.network()
            }
        }
    }
    func configHeader() {
        if self.one.zZbId.unwrap.isEmpty {
            self.one.zZbId = self.z_zb_id
        }
        jpTitleView.frame = CGRect(x: 0, y: 0, width: KSGlobal.screenW, height: 65)
        self.jpTitleView.recordApi = API.tender(.queryBidRecordList(z_zb_id: self.one.zZbId.unwrap, z_bid_id: self.one.zBidId.unwrap, z_staff_id: USERINFO.usrid.unwrap))
        
        jpTitleView.setChujiaShow(title: one.zTitle.unwrap, count: one.zBidCount.unwrap, price: one.zPrice.unwrap, unit: one.zLeastUnitNm.unwrap, rank: one.zRank.unwrap,z_end_price_rank: one.zEndPriceRank.unwrap,z_parallel: self.one.zParallel.unwrap)
        headView.addSubview(jpTitleView)
 
        let infoHeight = self.tbinfo_V.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
             self.tbinfo_V.frame = CGRect(x: 0, y: 65, width: KSGlobal.screenW, height: infoHeight)
             headView.frame = CGRect(x: 0, y: 0, width: KSGlobal.screenW, height: infoHeight + 65)
             headView.addSubview(tbinfo_V)
             self.tableView.tableHeaderView = headView
    }
    
    func configView() {
        
        
        if !appendWidget {
            itemSl.setCountViewMax(doubleTran(one.zNum))
            itemSl.setCountViewMin(doubleTran(one.zLeastNum))
            footbg.add(itemdw)
            footbg.add(itemr)
            footbg.add(itemdh)
            footbg.add(itemSl)
            
          
            
            var startPrice = 0.0
            var editable = false
            if doubleTran(self.one.zPrice) > 0 {
                startPrice = doubleTran(self.one.zPrice)
            } else if self.one.zZbPrice.doubleWrap > 0 {
                startPrice = self.one.zZbPrice.doubleWrap
            } else {
                editable = true
            }
            origTbPrice = startPrice

            
            
            
            if doubleTran(self.one.zRange) == 0 {// 幅度为0，用手输入
                footbg.add(itemjg_input)
        
                
                
            } else {
                if startPrice == 0 { // 幅度不为0，但是起始报价为0，用手输入
                    
                    footbg.add(itemjg_input)
                    
                    
                } else { // 幅度不为0，起始报价也不为0，用加减按钮
                    var maxV:Double = 1000000
                    var minV:Double = 0.0
                    if self.one.zType.unwrap == "0" {  // 卖标 的时候  起始价为最小价
                        if startPrice > 0 {
                            minV = Double(startPrice)
                        }
                    } else {  // 买标  的时候  起始价为最高价
                        if startPrice > 0 {
                            maxV = Double(startPrice)
                        }
                    }
                    footbg.add(itemjg)
                    itemjg.setCountViewMax(maxV)
                    itemjg.setCountViewMin(minV)
                    itemjg.setFuduNumber(doubleTran(self.one.zRange))

           
                    
                }
                
                
                
            }
            
            
            
            
            footbg.add(itemSM)
            if self.excuteType != .add {
                footbg.add(itemsj)
            }
            
            footbg.addSection(sectionx)
            footbg.add(submitButton)
            footerView.ks_height = footbg.frame.maxY
            self.tableView.tableFooterView = footerView
            appendWidget = true
        }
        
        
        
        
    }
    func configAction() {
      
        self.itemr.textValueChangeClo = { str in
            self.one.zName = str
        }
        self.itemdh.textValueChangeClo = { str in
            self.one.zTel = str
        }
        self.itemSM.textValueChangeClo = { str in
            self.one.zContent = str
        }
        itemSl.countViewChangeClo = { str in
            self.one.zBidNum = str
        }
        itemjg.countViewChangeClo = { str in
            self.one.zPrice = str
        }
        itemjg_input.textValueChangeClo = { str in
            self.one.zPrice = str
        }
        submitButton.button.addTouchUpInSideAction {_ in
            let count = self.form.validate().count
            guard count == 0 else {
                return
            }
            self.saveAction()
        }
    }
    func configDataSource() {
        if self.excuteType == .add {
            one.zName = PersonInfo!.faren
            one.zTel = PersonInfo!.providerTel
            one.zTbCompany = PersonInfo!.commpayNm
        }
        let tbTitle = "确认\(zyagetRest4Show(max: self.one.zMaxBidNo.unwrap, rest: self.one.zRestBidNo.unwrap))"
        submitButton.button.setTitle(tbTitle, for: .normal)
        
        if ( self.z_tb_status == "0" && self.z_zb_status == "2"  && zyagetRest4Judge(max: self.one.zMaxBidNo.unwrap, rest: self.one.zRestBidNo.unwrap) ) {
            if submitButton.superview.isNone {
                footbg.insertx(submitButton, preItem: sectionx) {
                    footerView.ks_height = footbg.frame.maxY
                    self.tableView.tableFooterView = footerView
                }
            }
        } else {
            if submitButton.superview.isSome {
                footbg.removex(submitButton) {
                    footerView.ks_height = footbg.frame.maxY
                    self.tableView.tableFooterView = footerView
                }
            }
        }
        itemdw.setVal(one.zTbCompany)
        itemr.setVal(one.zName)
        itemdh.setVal(one.zTel)
        itemsj.setVal(one.zCreateTm)
        itemSl.appearance.tailDesc = self.one.zLeastUnitNm.unwrap
        itemSl.updateTailDesc()
        itemjg.appearance.tailDesc = "元/\(self.one.zUnitNm.unwrap)"
        itemjg.updateTailDesc()
        
        var cur_num:Double = 0.0
        if let bidN = self.one.zBidNum {
            cur_num = doubleTran(bidN)
        } else {
            cur_num = doubleTran(one.zLeastNum)
            self.one.zBidNum = "\(cur_num.cleanZero)"
        }
        
        itemSl.setCountVCurrentValue(cur_num)
//        fjwoiefjo
        //todo 出价价格
        var startPrice = 0.0
        var editable = false
        if doubleTran(self.one.zPrice) > 0 {
            startPrice = doubleTran(self.one.zPrice)
        } else if self.one.zZbPrice.doubleWrap > 0 {
            startPrice = self.one.zZbPrice.doubleWrap
        } else {
            editable = true
        }
        origTbPrice = startPrice
        
        var showPrice = startPrice == 0 ? "" : "\(startPrice)"
        
        itemjg.setCountVCurrentValue(startPrice)
        itemjg_input.setVal(showPrice)
        if self.z_zb_id.isEmpty { // 查出价
            
        } else { // 查采购
            self.one.zContent = ""
        }
        itemSM.setVal(one.zContent)
    }
    
    func network() {
        KSNetwork.shared.doRequest(API.queryBidInfo(z_bid_id: z_bid_id)) { (data:BaseResult<ZyaZtbContentModel>) in
            if data.flag == TRUE {
                if let info = data.info_object {
                    self.one = info
                    self.configBtnState()
                    self.z_zb_status = info.zZbStatus.unwrap
                    self.z_tb_status = info.zStatus.unwrap
                    
                    
                    
                    if self.z_zb_status != "2" { // 发起销售出价 为 进行中的时候才会有  放弃
                        self.navigationItem.rightBarButtonItem = nil
                    }
                    if self.z_tb_status != "0" { // ----   参与销售出价  状态为 未中标才 有放弃
                        self.navigationItem.rightBarButtonItem = nil
                    }
                    if self.excuteType == .add {
                   
                    } else {
                        if self.z_tb_status == "2" { // 已放弃
                          
                        } else {
                        
                            
                            // 非首次加载，要提示排名变动
                            if self.networked {
                                if  self.orizPriceRank == info.zPriceRank.unwrap {
                                    KSToast("排名未变动")
                                } else {
                                    alertUtil(self, title: "排名变化",message: info.zPriceRank.unwrap,withCancel: false, operateS: [nameAction(name: "确定", action: { _ in
                                        if let clo = self.refreshClosure {
                                            clo()
                                        }
                                    })])
                                }
                                
                            } else {
                                self.orizPriceRank = info.zPriceRank.unwrap
                            }
                            
                      
                        }
                        
                    }
                    
//                    self.tbinfo_V.contentStr = self.one.jpInfo.unwrap
                    self.tbinfo_V.content1.multiLineTitleContentShow(contentStr: self.one.jpInfo.unwrap, fontx: 16)
                    
                    
                    self.configHeader()
            
                    self.insertIds2Update()
                    
                    
                    
                    
                    self.getDepositValue { (flag,value) in
                        self.depositRemain = doubleTran(value)
                        
                        
                        
                        self.performRow()
                    }
                    
                    
                }
                
                
            } else {
                KSToast(data.errorCombine.unwrap)
            }
            self.tableView.mj_header?.endRefreshing()
        }
        
      
    }
    func insertIds2Update() {
         
        GetNewestUtil_Z.shared.appendIds(ids: [self.one.zZbId.unwrap],type: .JP)
 
    }
    @objc func showRankTip() {
        var tipStr = ""
        if self.one.zType.unwrap == "0" {
            tipStr = "出价价格越高，排名越靠前"
        } else {
            tipStr = "出价价格越低，排名越靠前"
        }
        alertUtil(self, title: tipStr,withCancel: false, operateS: [nameAction(name: "确定", action: { (_) in
            
        })])
    }
    
    @objc func deleteAction() {
        
        
        let tipDesc = "放弃会被认为恶意出价并且保证金不退回，是否确认放弃？"
         alertUtil(self, title: tipDesc, operateS: [nameAction(name: "确定", action: { (_) in
            var api:API?
             // 放弃 操作
            api = API.abandonBidInfo(id_key: self.z_bid_id)
            
            KSNetwork.shared.doRequest(api!) { (data:BaseResult<OperateResult>) in
                if data.flag == TRUE {
                    if let clo = self.refreshClosure {
                        clo()
                    }
                    self.navigationController?.popViewController(animated: true)
                    
                } else {
                    KSToast(data.errorCombine.unwrap)
                }
            }
        })])
        
 
       
        
    }
    func  getAlertTipStr() -> String {
        "本次会消耗一次出价机会，您的出价价格是\(self.one.zPrice.unwrap)元，请再次核对您的出价价格，是否立即参与出价？"
    }
    func performRow () {
        
       
        configView()
        configDataSource()
    
     
        var startPrice = 0.0
        var editable = false
        if doubleTran(self.one.zPrice) > 0 {
            startPrice = doubleTran(self.one.zPrice)
        } else if self.one.zZbPrice.doubleWrap > 0 {
            startPrice = self.one.zZbPrice.doubleWrap
        } else {
            editable = true
        }
        origTbPrice = startPrice
        

         
        

        self.networked = true
    }
    
    func saveAction() {
       
        
        if doubleTran(self.one.zRange) == 0 {
            
        } else {
           
            
            
        }
        
        let vali = Validation()
        vali.required(value: one.zTbCompany, msg: "出价单位不为空")
        vali.required(value: one.zName, msg: "出价人不为空")
        vali.required(value: one.zTel, msg: "联系电话不为空")
        vali.required(value: one.zBidNum, msg: "出价数量不为空")
        vali.required(value: one.zPrice, msg: "出价价格不为空")

        
        guard vali.validate() else {
            return
        }
        
       
        
        
        
        if self.one.zZbPrice.doubleWrap > 0.0 {
            
            if self.one.zType.unwrap == "0" {  // 卖标
                guard doubleTran(self.one.zPrice) >= self.one.zZbPrice.doubleWrap else {
                    KSToast("出价价格不能低于采购价格")
                    return
                }
                
            } else {  // 买标
                guard doubleTran(self.one.zPrice) <= self.one.zZbPrice.doubleWrap else {
                    KSToast("出价价格不能高于采购价格")
                    return
                }
                
            }
            
        }
        
        if self.origTbPrice > 0 {
            if self.one.zType.unwrap == "0" {  // 卖标
                
                guard doubleTran(self.one.zPrice) >= self.origTbPrice else {
                    KSToast("出价价格不能低于参考价格或上次出价价格")
                    return
                }
            } else {  // 买标
                
                guard doubleTran(self.one.zPrice) <= self.origTbPrice else {
                    KSToast("出价价格不能高于参考价格或上次出价价格")
                    return
                }
            }
        }
        guard doubleTran(self.one.zPrice) > 0 else {
            KSToast("出价价格不能为0")
            return
        }
        
        if self.excuteType == .add {
            alertUtil(self, title: getAlertTipStr(), operateS: [nameAction(name: "确定", action: { (_) in
                
                var api:API?
                self.one.zClientSideTm = Date.nowTimeToSecond
                api = API.saveMytenderBidInfo(data: dictionaryToJson(self.one.dictionaryRepresentation()))
                
                
                KSNetwork.shared.doRequest(api!) { (data:BaseResult<OperateResult>) in
                    if data.flag == TRUE {
                        if let info = data.info_object {
                            
                            self.excuteType = .fix
                            self.z_bid_id = info.z_bid_id.unwrap
                            NotificationCenter.default.post(name: NSNotification.Name(rawValue: CALL_tenderinfo_REFRESH), object: nil)
                            self.configAddorFIx()
                            
                            
                            
                        } else {
                            KSToast("缺少出价id")
                        }
                        
                    } else {
                        KSToast(data.errorCombine.unwrap)
                    }
                }
            })])
        } else {
            alertUtil(self, title: "您的出价价格是\(self.one.zPrice.unwrap)元，请再次核对您的出价价格，是否立即参与出价？", operateS: [nameAction(name: "确定", action: { (_) in
                
                
                self.one.zClientSideTm = Date.nowTimeToSecond
                var api:API?
                
                api = API.updateMytenderBidInfo(data: dictionaryToJson(self.one.dictionaryRepresentation()))
                 
                KSNetwork.shared.doRequest(api!) { (data:BaseResult<OperateResult>) in
                    if data.flag == TRUE {
                        
                        NotificationCenter.default.post(name: NSNotification.Name(rawValue: CALL_tenderinfo_REFRESH), object: nil)
                        self.tableView.mj_header?.beginRefreshing()
                         
                    } else {
                        KSToast(data.message.unwrap)
                    }
                }
            })])
        }
        
    }
    
    
    
    
}
class ZyaAbandButton:UIButton {
  
    override func layoutSubviews() {
        super.layoutSubviews()
        // 设置title
        titleLabel?.frame = CGRect(x: 0 , y: 0, width: self.ks_width - 20, height: self.ks_height)
         // 设置imageView
        imageView?.frame = CGRect(x: self.ks_width - 20 , y: (self.ks_height - 20) / 2, width: 20, height: 20)
    
 
    }
}
